home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-02-04 | 6.0 KB | 216 lines | [TEXT/MPCC] |
- // ————• WASTE 3DMF Object—————————————————————————————————————————————————————————————
- // ———• by Chris K. Thomas, ckt@best.com
-
- // ——• 5 Feb 96 ckt 1.0b1 - rev to current QD3D interface.
- // ——• 4 Jun 95 ckt 1.0a1 - created.
- // ——• Still need a way to set kViewerSize dynamically
-
- // ————• Includes——————————————————————————————————————————————————————————————————————
-
- #include "WEObject3D.h" // ——• ourself
- #include "QD3DViewer.h" // ——• QD3D viewer
-
- // ————• Macros————————————————————————————————————————————————————————————————————————
-
- #define ThrowIfOSErr_(x) if(x != noErr) goto Exit
-
- // ————• Constants—————————————————————————————————————————————————————————————————————
-
- static const Point kViewerSize = {100, 100};
-
- // ————• Instance Variables————————————————————————————————————————————————————————————
-
- static CGrafPtr sDefaultPort = NULL;
- // * if port is NULL, we just use the parent WASTE port
-
- // ————• Static Prototypes—————————————————————————————————————————————————————————————
-
- static pascal OSErr HandleNew3D(Point *defaultObjectSize, WEObjectReference objectRef);
- static pascal OSErr HandleDispose3D(WEObjectReference objectRef );
- static pascal OSErr HandleDraw3D(Rect *destRect, WEObjectReference objectRef );
- static pascal Boolean HandleClick3D(Point hitPt, short modifiers,
- long clickTime, WEObjectReference objectRef);
-
- // ————• MixedMode——————————————————————————————————————————————————————————————————————
-
- static UniversalProcPtr sNew3DRD;
- static UniversalProcPtr sDispose3DRD;
- static UniversalProcPtr sDraw3DRD;
- static UniversalProcPtr sClick3DRD;
-
- // ————• Installer——————————————————————————————————————————————————————————————————————
-
- OSErr WEObj3DInstall(WEHandle inWaste)
- {
- OSErr theErr = noErr;
-
- // * mixed mode magic
-
- if(sNew3DRD == NULL)
- {
- sNew3DRD = NewWENewObjectProc(HandleNew3D);
- sDispose3DRD = NewWEDisposeObjectProc(HandleDispose3D);
- sDraw3DRD = NewWEDrawObjectProc(HandleDraw3D);
- sClick3DRD = NewWEClickObjectProc(HandleClick3D);
- }
-
- // * install
-
- theErr = WEInstallObjectHandler('3DMF', weNewHandler, sNew3DRD, inWaste);
- ThrowIfOSErr_(theErr);
-
- theErr = WEInstallObjectHandler('3DMF', weDisposeHandler, sDispose3DRD, inWaste);
- ThrowIfOSErr_(theErr);
-
- theErr = WEInstallObjectHandler('3DMF', weDrawHandler, sDraw3DRD, inWaste);
- ThrowIfOSErr_(theErr);
-
- theErr = WEInstallObjectHandler('3DMF', weClickHandler, sClick3DRD, inWaste);
- ThrowIfOSErr_(theErr);
-
- Exit:
- return theErr;
- }
-
- // ————• Setting info ———————————————————————————————————————————————————————————————————
- // ——• this is to be used when you're doing skanky things like
- // ——• changing WASTE's port to an offscreen one of your own only
- // ——• when it's drawing
- // ——•
- // ——• (this could become a general utility for all WEObjs)
-
- OSErr WEObj3DSetDefaultPort(CGrafPtr inPort)
- {
- sDefaultPort = inPort;
-
- return noErr;
- }
-
-
- // ————• New handler—————————————————————————————————————————————————————————————————————
- pascal OSErr HandleNew3D(Point *outDefaultSize, WEObjectReference inObjectRef)
- {
- OSErr theErr = noErr;
- Rect viewFrame;
- TQ3ViewerObject curViewer;
- Handle data;
- CGrafPtr wastePort;
- WEHandle parentWaste;
-
- // * get incoming 3DMF data
- data = WEGetObjectDataHandle(inObjectRef);
-
- HLockHi(data);
-
- // * use initial frame starting at origin
- viewFrame.left = viewFrame.top = 0;
- viewFrame.right = outDefaultSize->h = kViewerSize.h;
- viewFrame.bottom = outDefaultSize->v = kViewerSize.v;
-
- // * Q3ViewerNew needs a port in which to draw
- if(sDefaultPort == NULL)
- {
- // * use parent port
- parentWaste = WEGetObjectOwner(inObjectRef);
- theErr = WEGetInfo(wePort, &wastePort, parentWaste);
- ThrowIfOSErr_(theErr);
- }
- else
- {
- // * use user-specified port
- wastePort = sDefaultPort;
- }
-
- // * create the viewer and store it for later reference
- curViewer = Q3ViewerNew(wastePort, &viewFrame, kQ3ViewerDefault | kQ3ViewerDrawFrame);
- WESetObjectRefCon(inObjectRef, (long)curViewer);
- ThrowIfOSErr_(theErr);
-
- // * add data
- theErr = Q3ViewerUseData (curViewer, *data, GetHandleSize(data));
-
- Exit:
- return theErr;
- }
-
- // ————• Dispose handler—————————————————————————————————————————————————————————————————
- pascal OSErr HandleDispose3D(WEObjectReference inObjectRef)
- {
- OSErr theErr = noErr;
- TQ3ViewerObject curViewer;
- Handle data;
-
- // * retrieve viewer
- curViewer = (TQ3ViewerObject)WEGetObjectRefCon(inObjectRef);
-
- // * dispose viewer
- theErr = Q3ViewerDispose(curViewer);
-
- // * dispose data
- data = WEGetObjectDataHandle(inObjectRef);
- DisposeHandle(data);
-
- return theErr;
- }
-
- // ————• Draw handler————————————————————————————————————————————————————————————————————
- pascal OSErr HandleDraw3D (Rect *inDestRect, WEObjectReference inObjectRef)
- {
- OSErr theErr = noErr;
- WEHandle parentWaste;
- TQ3ViewerObject curViewer;
- CGrafPtr wastePort, curPort;
-
- // * retrieve viewer & it's port
- curViewer = (TQ3ViewerObject)WEGetObjectRefCon(inObjectRef);
- curPort = Q3ViewerGetPort(curViewer);
-
- // * get parent port and draw using that
- parentWaste = WEGetObjectOwner(inObjectRef);
- theErr = WEGetInfo(wePort, &wastePort, parentWaste);
-
- if(wastePort != curPort)
- {
- theErr = Q3ViewerSetPort(curViewer, wastePort);
- ThrowIfOSErr_(theErr);
- }
-
- // * use new rectangle
- theErr = Q3ViewerSetBounds(curViewer, inDestRect);
- ThrowIfOSErr_(theErr);
-
- // * draw
- theErr = Q3ViewerDraw(curViewer);
-
- // * restore port, if necessary
- if(wastePort != curPort)
- {
- theErr = Q3ViewerSetPort(curViewer, curPort);
- ThrowIfOSErr_(theErr);
- }
-
- Exit:
- return theErr;
- }
-
- // ————• Click handler———————————————————————————————————————————————————————————————————
-
- pascal Boolean HandleClick3D(Point hitPt, short modifiers,
- long /*clickTime*/, WEObjectReference inObjectRef)
- {
- EventRecord fake;
- TQ3ViewerObject curViewer;
-
- // * retrieve viewer
- curViewer = (TQ3ViewerObject)WEGetObjectRefCon(inObjectRef);
-
- // * simulate click event
- fake.where = hitPt;
- LocalToGlobal(&fake.where);
- fake.when = TickCount();
- fake.what = mouseDown;
- fake.modifiers = modifiers;
- fake.message = 0;
-
- return (Q3ViewerEvent(curViewer, &fake));
- }